<?php
/**
 * Holds class DataObject
 *
 * @author Mark
 *
 * @package Library
 */

/**
 * Data object base
 *
 * @deprecated
 * @author Mark
 */
abstract class DataObject {

	/**
	 * Data fields
	 * @var array $_field
	 */
	protected $_field = array();

	/**
	 * Data items
	 * @var array $_item
	 */
	protected $_item = array();

	/**
	 * Constructor
	 *
	 * @return void
	 */
	public function __construct() {
		//
	}

	/**
	 * Returns data
	 *
	 * @param string $key
	 * @throws Exception
	 * @return string
	 */
	public function __get($key) {
		if(!in_array($key, $this->_field)) {
			throw new Exception('Item ' . $key . ' does not exist');
		}
		return isset($this->_item[$key]) ? $this->_item[$key] : null;
	}

	/**
	 * Checks whether variable is set
	 *
	 * @param string $key
	 * @return boolean
	 */
	public function __isset($key) {
		return isset($this->_item[$key]);
	}

	/**
	 * Sets data
	 *
	 * @param string $key
	 * @param string $value
	 * @throws Exception
	 * @return void
	 */
	public function __set($key, $value) {
		if(!in_array($key, $this->_field)) {
			throw new Exception('Item ' . $key . ' does not exist');
		}
		$this->_item[$key] = $value;
	}

}
